package com.demo.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.demo.data.Result;
import com.demo.entity.TWorkorder;
import com.demo.service.ITWorkorderService;
import com.demo.service.impl.TWorkorderServiceImpl;
import com.demo.vo.TTAndTWVoDemo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2022-08-02
 */
@RestController
@RequestMapping("/t-workorder")
@Api(value = "demo")
public class TWorkorderController {


    @Autowired
    private ITWorkorderService workorderService;


    @RequestMapping("/demo")
    public String demo(){
        return "ok";
    }

    @GetMapping("selectList")
    public List<TWorkorder> selectList(){
        List<TWorkorder> tWorkorderList = workorderService.selcetList();
        return tWorkorderList;
    }

    @GetMapping("getPageDemo")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize" ,value = "每页条数" ,required = false , paramType = "query"),
            @ApiImplicitParam(name = "pageNum" , value = "当前页数" , required = false , paramType = "query")
    })
    public Result getPageDemo(@RequestParam(defaultValue = "1")Integer pageNum,
                              @RequestParam(defaultValue = "5")Integer pageSize){
        IPage<TWorkorder> crudDemoPage = workorderService.selectPageDemo(pageNum , pageSize);
        return Result.ok().setData(crudDemoPage);
    }

    @ApiOperation("两表联查")
    @GetMapping("getTWAndTT")
    public Result getTWAndTT(){
        List<TTAndTWVoDemo> ttAndTWVoDemoList = workorderService.selectGetTWAndTT();
        return Result.ok().setData(ttAndTWVoDemoList);
    }
}
